package cn.com.niit.socketio;

import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.annotation.OnConnect;
import com.corundumstudio.socketio.annotation.OnDisconnect;
import org.springframework.stereotype.Component;

/**
 * Socketio消息处理器
 */
@Component
public class MessageEventHandler {
    /**
     * 客户端连接的时候触发
     *
     * @param client
     */
    @OnConnect
    public void onConnect(SocketIOClient client) {
        //System.out.println("客户端:" + client.getSessionId() + "已连接");
        //新的客户端进行连接后，开启新的线程，读取kakfa数据并发到给此客户端
        new SocketThread(client).start();
    }

    /**
     * 客户端关闭连接时触发
     *
     * @param client
     */
    @OnDisconnect
    public void onDisconnect(SocketIOClient client) {
        //System.out.println("客户端:" + client.getSessionId() + "断开连接");
        //客户端关闭后，停止对应的socket连接，释放资源
        client.disconnect();
    }
}